﻿<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

    <title></title>
    <script src="Resource/jquery-1.10.2.js"></script>
    <script src="Resource/Core.js"></script>
    <script src="Resource/CheckboxComponent.js"></script>
</head>
<body>
    全选:<input type="checkbox" id="ck1" />

    单个:<input id="1" type="checkbox" tag="ck" />
    单个:<input id="2" type="checkbox" tag="ck" />
    单个:<input id="3" type="checkbox" tag="ck" />
    单个:<input id="4" type="checkbox" tag="ck" />
    单个:<input id="5" type="checkbox" tag="ck" />
    单个:<input id="6" type="checkbox" tag="ck" />
    单个:<input id="7" type="checkbox" tag="ck" />
</body>
</html>
<script type="text/javascript">
    $("#ck1").ckProcess({
        items: $("input[type=checkbox][tag=ck]"),
        itemCallback: ic
    });

    function ic() {
        var arg = arguments[0];
        if (arg.checked) {
            window.console.log("ID:" + arg.id + "被选中!");
        }
        else {
            window.console.log("ID:" + arg.id + "已经取消选中!");
        }
    }

    var arr = new Array();
    arr.push({ name: "a1", time: "2012", money: "100" });
    arr.push({ name: "a2", time: "2012", money: "100" });
    //arr.push({ name: "a", time: "2012", money: "100" });
    //arr.push({ name: "a", time: "2012", money: "100" });
    //arr.push({ name: "b", time: "2013", money: "100" });
    //arr.push({ name: "b", time: "2013", money: "100" });
    //arr.push({ name: "b", time: "2012", money: "100" });
    //arr.push({ name: "c", time: "2014", money: "100" });
    //arr.push({ name: "c", time: "2012", money: "100" });
    //arr.push({ name: "c", time: "2014", money: "100" });
    //arr.push({ name: "d", time: "2012", money: "100" });
    //arr.push({ name: "d", time: "2012", money: "100" });
    //arr.push({ name: "e", time: "2012", money: "100" });


    var s = jQuery.extend(true, [], arr);


    function getType(o) {
        var _t;
        return ((_t = typeof (o)) == "object" ? o == null && "null" || Object.prototype.toString.call(o).slice(8, -1) : _t).toLowerCase();
    }
    function extend(destination, source) {
        for (var p in source) {
            if (getType(source[p]) == "array" || getType(source[p]) == "object") {
                destination[p] = getType(source[p]) == "array" ? [] : {};
                arguments.callee(destination[p], source[p]);
            }
            else {
                destination[p] = source[p];
            }
        }
    }

    var temp = [];
    extend(temp, arr);

    for (var i = 0; i < temp.length; i++) {
        delete temp[i].money;
        var a = temp[i].money;
        var b = arr[i].money;
    }

    var c = temp.unique();

    for (var j = 0; j < c.length; j++) {
        for (var i = 0; i < arr.length; i++) {
            if (c[j].name == arr[i].name && c[j].time == arr[i].time) {
                if (c[j].money == undefined) {
                    c[j].money = 0;
                }
                c[j].money = parseInt(arr[i].money) + parseInt(c[j].money);
            }
        }
    }

</script>
